package com.hongxun.budget.ui.fragment.tk;

import android.widget.TextView;

import com.hongxun.budget.R;
import com.hongxun.budget.greendao.DDeviceOldEntityDao;
import com.hongxun.budget.ui.fragment.BaseListFragment;
import com.hongxun.budget.utils.DBUtils;
import com.hongxun.budget.utils.GreenDaoManager;
import com.hongxun.budget.utils.SPUtils;
import com.hongxun.greenentity.tk.DDeviceOldEntity;
import com.jessewu.library.SuperAdapter;
import com.jessewu.library.view.ViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2018/8/17.
 */

public class DeviceInfoFragment extends BaseListFragment {


    List<DDeviceOldEntity> datas = new ArrayList<>();
    SuperAdapter<DDeviceOldEntity> adapter;

    @Override
    public SuperAdapter getAdapter() {
        return adapter = new SuperAdapter<DDeviceOldEntity>(R.layout.content_fragment_device_info) {
            @Override
            public void bindView(ViewHolder viewHolder, DDeviceOldEntity d, int i) {
                ((TextView) viewHolder.getView(R.id.lineName)).setText(DBUtils.getLineNameWithPPname(d.getPPGuid()));
                ((TextView) viewHolder.getView(R.id.work_txt)).setText(d.getDRWork());
                ((TextView) viewHolder.getView(R.id.name)).setText(d.getDRName());
                ((TextView) viewHolder.getView(R.id.parameter)).setText(d.getDRParameter());
                if(!d.getDROpinion().equals("-9")){
                    ((TextView) viewHolder.getView(R.id.process_type)).setText(DBUtils.getBDataDictionaryEntity("opinion_type", d.getDROpinion()).getDValue());
                }else{
                    ((TextView) viewHolder.getView(R.id.process_type)).setText("本项目利旧");
                }
            }
        };
    }

    @Override
    public  void initView() {
        super.initView();
        datas.addAll(GreenDaoManager.getInstance().getmDaoSession().getDDeviceOldEntityDao().queryBuilder().where(
                DDeviceOldEntityDao.Properties.PGuid.eq(SPUtils.get(context, "project_guid", ""))
                , DDeviceOldEntityDao.Properties.DRDatastate.notEq("删除")
        ).list());
        adapter.setData(datas);
        adapter.setEmptyDataView(R.layout.view_empty);
    }
}
